<?php
function ad_config() {
	$prev = V('g:ad_preview');
	$data = ''; 
	//@todo 从数据库或memcache读配置数据
	$router = APP::getRequestRoute();
	//DD('ad.getUsingAd');
	$rs = DS('ad.getUsingAd', '', 1, $router);
	//$global_ad = DS('ad.getUsingAd', '', 1, 'global');
	//$rs = array_merge($rs, $global_ad);
	for ($i=0, $count=count($rs); $i < $count; $i++) {
		// 如果是对联，并设置了“按天展现”，并且cookie存在，则不输出配置
		if (in_array($rs[$i]['flag'], array('global_left', 'global_right')) &&
			!empty($rs[$i]['config']) && ($cfg= json_decode($rs[$i]['config'], true)) &&
			isset($cfg['topic_get']) && $cfg['topic_get'] == 2 &&
			V('c:ad_' . $rs[$i]['page'] . '_' . $rs[$i]['flag']. '_hide', false)) {
				continue;
		}
		$config = array();
		if (empty($rs[$i]['config'])) {
			$rs[$i]['config'] = '{}';
		}
		$config['flag'] = $rs[$i]['flag'];
		$config['page'] = $rs[$i]['page'];
		$config['cfg'] = json_decode($rs[$i]['config'], true);
		$data[] = $config;
	}

	// 如果是预览一广告，则覆盖原有数据
	if ($prev) {
		$data[$prev] = V('r');
	}
	$data = json_encode($data);
	return $data;
}

?>
